package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.ActivityDO;
import com.example.lotterysystem.dao.dataobject.ActivityPrizeDO;
import com.example.lotterysystem.dao.dataobject.PrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description: 从数据库中获取活动创建数据
 * User: Spider-Man
 * Date: 2025-09-12
 * Time: 14:50
 */
@Mapper
public interface ActivityMapper {

    @Insert("insert into activity (activity_name, description, status)" +
            " values (#{activityName}, #{description}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty ="id", keyColumn ="id")
    int insert(ActivityDO activityDO);

    //获取活动数量
    @Select("select count(1) from activity")
    int count();

    @Select("select * from activity order by id desc limit #{offset},#{pageSize}")
    List<ActivityDO> selectActivityList(@Param("offset") Integer offset,
                                  @Param("pageSize") Integer pageSize);


    //查询活动信息(根据id查询)
    @Select("select * from activity where id = #{id}")
    ActivityDO selectById(Long id);

    /**
     * 更新活动状态
     */
    @Update("update activity set status = #{status} where id = #{id}")
    void updateStatus(@Param("id")Long id,
                      @Param("status")String status);

}
